﻿using ModernChannel.Model.Interface;
using ModernChannel.Model.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common.Util;

namespace ModernChannel.Provider
{
    public class ModelCatProvider : GenericProvider, IModelCatProvider
    {
        public List<ModelCat> SearchModelCats(out int totalrecord, string model = null, int pagesize = 0, int pageindex = 0)
        {
            var querry = repository.GetQuery<ModelCat>();
            if (!model.IsNullOrWhiteSpace())
            {
                var modelCheck = model.Trim().ToUpper();
                querry = querry.Where(x => x.Model.ToUpper().Contains(modelCheck));
            }
            totalrecord = querry.Count();
            if (pagesize > 0 && pageindex >= 0)
            {
                querry = querry.OrderBy(x => x.ProdL1).ThenByDescending(x => x.CreateDate);
                querry = querry.Skip(pageindex * pagesize).Take(pagesize);
            }
            return querry.ToList();
        }
    }
}
